<!-- AUTHORS: Yiwei (Alan) Han, Kevin Lam -->

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="java.util.Calendar"%>
<%@ page import="java.util.TimeZone"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<script language="JavaScript" type="text/javascript" src="/js/navbar.js"></script>
<script language="JavaScript" type="text/javascript" src="/js/login.js"></script>
<link rel="stylesheet" type="text/css" media="all"
	href="/style/header.css" />
</head>
<%
	String cookieName = "user";
	Cookie cookies[] = request.getCookies();
	Cookie myCookie = null;
	if (cookies != null) {
		for (int i = 0; i < cookies.length; i++) {
			if (cookies[i].getName().equals(cookieName)) {
				myCookie = cookies[i];
				break;
			}
		}
	}
	String show;
	Calendar c = Calendar.getInstance(TimeZone.getTimeZone("PST"));
	String greeting = "";
	if (c.get(Calendar.HOUR_OF_DAY) >= 0
			&& c.get(Calendar.HOUR_OF_DAY) < 12)
		greeting = "Good morning, ";
	else if (c.get(Calendar.HOUR_OF_DAY) >= 11
			&& c.get(Calendar.HOUR_OF_DAY) < 18)
		greeting = "Good afternoon, ";
	else
		greeting = "Good evening, ";
	if (myCookie != null) {
		show = "<li class=\"navelement\">" + greeting + "<b><a href=\"/preferences.jsp\">"
				+ myCookie.getValue() + "</a></b></li>";
		//show += "<li onmouseover='setClass(this,\"li_mouseover\")' onmouseout='setClass(this,\"li_mouseout\")'  class=\"li_mouseout\"><a href=\"/\">Settings</a></li>";
		show += "<li onmouseover='setClass(this,\"li_mouseover\")' onmouseout='setClass(this,\"li_mouseout\")' onclick=\"javascript:logout()\" class=\"li_mouseout\"><b>Logout</b></li>";
	} else {
		show = "<li onmouseover='setClass(this,\"li_mouseover\")' onmouseout='setClass(this,\"li_mouseout\")' onclick=\"window.location ='/register'\" class=\"li_mouseout\"><b>Register</b></p>";
		show += "<li onmouseover='setClass(this,\"li_mouseover\");' onmouseout='setClass(this,\"li_mouseout\");' onclick='toggleLogin()' class=\"li_mouseout\"><b>Login</b></p>";
	}
%>
<body>
	<div id="navbar">
		<ul>
			<%=show%>

		</ul>
		<ul id="common-nav">
			<%
			String worklistHtml = "";
			if(myCookie != null) {
				String user = myCookie.getValue();
				worklistHtml = "<li class='navitem'><a href='/worklist?email="+user+"'>My Worklist</a></li>"; 
			}
			%>
			<%=worklistHtml %>
			<li class="navitem"><a href="/">Home</a></li>			
		</ul>
		<%@ include file="login.jsp"%>
	</div>
</body>
</html>